package com.logger;

import android.app.Application;
import android.content.Context;
import android.content.res.AssetManager;

import com.logger.loader.ConfigLoader;
import com.logger.loader.Loader;
import com.logger.loader.PropertiesLoader;

import java.io.IOException;
import java.io.InputStream;

/**
 * 日志框架配置
 * Created by chenxunlin01 on 2016/1/16.
 */

public class Config {

    private Application application;

    public Application getApplication() {
        return application;
    }

    public void setApplication(Application application) {
        this.application = application;
    }

    public Loader getLoader() {
        return getAssetConfig(application);
    }

    private Loader getAssetConfig(Context ctx) {
        AssetManager am = ctx.getAssets();
        try {
            InputStream ins = am.open(ConfigLoader.CONFIG_FILE);
            if (ins == null) {
                return null;
            }
            return new PropertiesLoader(ins);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
